using System;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity;
using System.Linq;

namespace HouseManger.Model
{
    public partial class HouseEntity : DbContext
    {
        public HouseEntity()
            : base("name=HouseEntity")
        {
        }

        public virtual DbSet<HouseInfo> HouseInfo { get; set; }
        public virtual DbSet<HouseType> HouseType { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<HouseInfo>()
                .Property(e => e.Area)
                .HasPrecision(18, 0);

            modelBuilder.Entity<HouseInfo>()
                .Property(e => e.Price)
                .HasPrecision(18, 0);

            modelBuilder.Entity<HouseInfo>()
                .Property(e => e.Describe)
                .IsUnicode(false);

            modelBuilder.Entity<HouseInfo>()
                .Property(e => e.Years)
                .HasPrecision(18, 0);

            modelBuilder.Entity<HouseType>()
                .HasMany(e => e.HouseInfo)
                .WithRequired(e => e.HouseType)
                .HasForeignKey(e => e.TypeId)
                .WillCascadeOnDelete(false);
        }
    }
}
